export default Object.assign(
  {},
  {
    getOptions: function(options) {
      const { chartData } = options
      const grid = {
        top: '5%',
        left: '3%',
        right: '15%',
        bottom: '-5%',
        containLabel: true
      }
      const legend = {
        show: false
      }
      const tooltip = {
        show: true,
        trigger: 'axis',
        valueFormatter: value => (value * 100).toFixed(2) + '%',
        axisPointer: {
          // Use axis to trigger tooltip
          type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
        }
      }
      const xAxis = {
        show: false
        // boundaryGap:false
      }
      const yAxis = {
        type: 'category',
        data: chartData?.labels
      }
      const series = chartData?.series
        .map(item => {
          return {
            name: item.label,
            type: 'bar',
            barGap: '-100%',
            label: {
              show: true,
              position: item.label === '十四五目标值' ? 'right' : 'insideRight',
              // formatter: params => Math.round(params.value * 100) + '%',
              formatter: function (params) {
                if (params.value > 0) {
                  return Math.round(params.value * 100) + '%'
                } else {
                  return ''
                }
              },
              fontSize: '10px'
            },
            emphasis: {
              focus: 'series'
            },
            barWidth: '80%',
            data: item.data
          }
        })
        .reverse()
      const color = ['#FF9600', '#FFB768', '#DDDDDD']
      return { grid, tooltip, legend, xAxis, yAxis, series, color }
    },

    render: function(instance, options) {
      instance && instance.setOption(options, true)
      return instance
    }
  }
)
